﻿using System;
using System.Diagnostics;
using Microsoft.Practices.CompositeWeb;
using Microsoft.Practices.ObjectBuilder;

namespace CSC440TeamOne.Admin.Views
{
    /// <summary>
    /// Name - UserManualPresenter.cs
    /// Description - 
    /// Programmer - CSC440 Team One
    /// Date coded - 11/27/2011
    /// Arguments - IBusinessService
    /// Variables - None
    /// Files accessed by this code artifact - None
    /// Files changed by this code artifact - None
    /// I/O - None
    /// Error Handling - None
    /// Modifications -
    ///     1.0 - Initial coding
    /// Known Faults -
    ///     1.0 - None known
    /// </summary>
    public class UserManualPresenter : Presenter<IUserManualView>
    {
        private IAdminController _controller;

        /// <summary>
        /// Initializes a new instance of the <see cref="UserManualPresenter"/> class.
        /// </summary>
        /// <param name="controller">The controller.</param>
        public UserManualPresenter([CreateNew] IAdminController controller)
        {
            _controller = controller;
        }

        /// <summary>
        /// Called when [view loaded].
        /// </summary>
        public override void OnViewLoaded()
        {

        }

        /// <summary>
        /// Called when [view initialized].
        /// </summary>
        public override void OnViewInitialized()
        {
            try
            {
                Debug.Write("start UserManualPresenter.OnViewInitialized");

                var currentIndex = View.CurrentSectionId;

                var model = _controller.GetUserManualModelByCurrentIndex(currentIndex);

                View.Show(model);

                Debug.Write("end UserManualPresenter.OnViewInitialized");
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());

                throw;
            }
        }

        /// <summary>
        /// Called when [save].
        /// </summary>
        public void OnSave()
        {
            try
            {
                Debug.Write("start UserManualPresenter.OnSave");

                var currentIndex = View.CurrentSectionId;

                var model = _controller.GetUserManualModelByCurrentIndex(currentIndex);

                View.Update(model);

                _controller.SaveUserManualModel(model);

                View.OnSaveCompleted(model);

                Debug.Write("end UserManualPresenter.OnSave");
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());

                throw;
            }
        }

        /// <summary>
        /// Called when [add section].
        /// </summary>
        public void OnAddSection()
        {
            try
            {
                Debug.WriteLine("start UserManualPresenter.OnAddSection");

                var sectionid = View.CurrentSectionId;

                var model = _controller.GetUserManualModelByCurrentIndex(sectionid);

                _controller.AddUserManualSection(model);

                View.OnAddSectionCompleted(model);

                Debug.WriteLine("end UserManualPresenter.OnAddSection");
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());

                throw;
            }
        }

        /// <summary>
        /// Called when [add content].
        /// </summary>
        public void OnAddContent()
        {
            try
            {
                Debug.WriteLine("start UserManualPresenter.OnAddContent");

                var sectionid = View.CurrentSectionId;

                var model = _controller.GetUserManualModelByCurrentIndex(sectionid);

                View.Update(model);

                _controller.AddUserManualContent(model);

                View.OnAddContentCompleted(model);

                Debug.WriteLine("end UserManualPresenter.OnAddContent");
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());

                throw;
            }
        }

        /// <summary>
        /// Called when [preview].
        /// </summary>
        public void OnPreview()
        {
            try
            {
                Debug.WriteLine("start UserManualPresenter.OnAddContent");

                var sectionid = View.CurrentSectionId;

                var model = _controller.GetUserManualModelByCurrentIndex(sectionid);

                View.Update(model);

                View.OnPreviewCompleted(model);

                Debug.WriteLine("end UserManualPresenter.OnPreview");
            }
            catch (Exception ex)
            {
                Trace.TraceError(ex.ToString());

                throw;
            }
        }
    }
}




